// count
import React, { Component } from "react";
import store from "../../redux/store";
import { createIncreamentAction, createDecreamentAction, createIncreamentAsync } from "../../redux/count_action";
export default class Count extends Component {
  increament = () => {
    const { value } = this.selectNumber;
    /* store.dispatch({
      type: "increament",
      data: value*1,
    }); */
    store.dispatch(createIncreamentAction(value * 1));
  };
  increamentAsync = () => {
    console.log("increamentAsync过一会");
    const { value } = this.selectNumber;
    store.dispatch(createIncreamentAsync(value * 1, 1000));
  };
  increamentAsync2 = () => {
    console.log("increamentAsync过一会2");
    const { value } = this.selectNumber;
    createIncreamentAsync(value * 1, 2000);
  };
  render() {
    console.log(store.getState(), "getstate");
    const num = store.getState();
    return (
      <div>
        <h3>当前为{num}</h3>
        <select ref={(n) => (this.selectNumber = n)}>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
        </select>
        <br />
        <button onClick={this.increament}>+</button>
        <button onClick={this.decreament}>-</button>
        <button onClick={this.increamentIfOdd}>奇数才能加</button>
        <button onClick={this.increamentAsync}>过一会再加</button>
        <button onClick={this.increamentAsync2}>过一会再加2</button>
      </div>
    );
  }
}
